<template>

  <el-row type="flex" justify="space-between" align="middle" style="width: 100%; height: 50px; ">
    <el-col>
      <!--通过 判断 显示的内容 -->
      <strong v-if="istoop"><i class="el-icon-s-home" />{{ treeNode.name }}</strong>
      <span v-else><i class="el-icon-user-solid" />  {{ treeNode.name }}</span>

    </el-col>
    <el-col :span="4">
      <el-row type="flex" justify="end">
        <!-- 两个内容 -->
        <el-col>{{ treeNode.manager }}</el-col>
        <el-col>
          <!-- 下拉菜单 element -->
          <el-dropdown>
            <span>
              操作<i class="el-icon-arrow-down" />
            </span>
            <!-- 下拉菜单 -->
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="addDepartments">添加部门</el-dropdown-item>
              <el-dropdown-item v-if="!istoop" @click.native="deletedatabase">删除部门</el-dropdown-item>
              <el-dropdown-item v-if="!istoop" @click.native="editDepartment">编辑部门</el-dropdown-item>

            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { deletedatabase } from '@/api/depaartments'
export default {
  props: {
    treeNode: {
      type: Object,
      required: true
    },
    istoop: {
      type: Boolean,
      required: true
    }

  },
  methods: {
    // 删除部门
    async deletedatabase() {
      try {
        await this.$confirm('是否确认删除')
        await deletedatabase(this.treeNode.id)
        this.$message.success('删除成功')
        // 更新页面
        this.$emit('deletedatabase')
      } catch (error) {
        console.log(error)
      }
    },
    // 添加部门
    addDepartments() {
      this.$emit('addDepartments', this.treeNode)
    },
    // 编辑部门
    editDepartment() {
      console.log(this.treeNode.id)

      this.$emit('editDepartment', this.treeNode)
    }

  }
}
</script>

<style>

.el-dropdown-selfdefine{
  font-size:20px;
}
</style>
